exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  doAddOrUpdateCellAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const postData = _this.post('id,BGID,area_code,area_id,BGSQua,Note,scope_path,color');
      const CellService = _this.service('cms/CellService');
      const res = yield CellService.doAddOrUpdateCell(postData);
      if (!res.error) {
        aj.success = res.success;
        aj.result = res.result;
        aj.msg = res.msg;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this.json(aj);
    })();
  }

  /**
   * 查询所有单元网格（分页）
   *
   * @returns
   */
  queryAllCellPageListAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const GetData = _this2.get('page,pageSize,area_id');
      const CellService = _this2.service('cms/CellService');
      const res = yield CellService.getCellListPage(GetData);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this2.json(aj);
    })();
  }
  /**
   * 通过区域id查询单元格信息
   */
  queryCellListByAreaIdAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const GetData = {
        area_id: _this3.get('area_id')
      };
      const CellService = _this3.service('cms/CellService');
      const res = yield CellService.getCellListById(GetData);
      if (!res.error) {
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this3.json(aj);
    })();
  }
  /**
   * 查询单元格列表信息
   *
   * @returns
   */
  querCellAllListAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const CellService = _this4.service('cms/CellService');
      const res = yield CellService.getCellAllList();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this4.json(aj);
    })();
  }

  /**
   * 删除单元格
   *
   * @returns
   */
  deltCellAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const postData = {
        id: _this5.post('id')
      };
      const CellService = _this5.service('cms/CellService');
      const res = yield CellService.deltCell(postData);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this5.json(aj);
    })();
  }

  /**
   * 通过坐标查询所属社区和所属单元格
   *
   * @returns
   */
  queryAreaAndBGIDByCoordinateAction() {
    var _this6 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const postData = {
        point: _this6.post('point')
      };
      console.log(postData);
      const CellService = _this6.service('cms/CellService');
      const res = yield CellService.queryAreaAndBGIDByCoordinate(postData);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this6.json(aj);
    })();
  }
};